<?php
// ====================================================
// filename: wl001_login.php
// summary: 系统登录画面_登录检验
// ====================================================
require_once ("../init.php");

try {
    
    // 用户是否登录
    if (! Login::islogin()) {
        
        $login = $_POST['login'];
        $pw = $_POST['pw'];
        
        if (! isset($login)) {
            echo json_encode(array(
                'success' => false,
                'msg' => "登陆账号不能为空，请输入！"
            ));
            return;
        }
        if (! isset($pw)) {
            echo json_encode(array(
                'success' => false,
                'msg' => "密码不能为空，请输入！"
            ));
            return;
        }
        
        $wlu02 = new wlu02tbx();
        $u02_1res = $wlu02->sel_wlu02tbx_check_login($login);
        if (count($u02_1res) == 0) {
            echo json_encode(array(
                'success' => false,
                'msg' => "输入的登录账号不存在，请确认！"
            ));
            return;
        }
        
        $u02_2res = $wlu02->sel_wlu02tbx_check_pw($login, $pw);
        if (count($u02_2res) == 0) {
            echo json_encode(array(
                'success' => false,
                'msg' => "输入的密码有误，请重新输入！"
            ));
            return;
        }
        
        // 登录成功
        $_SESSION['wl_islogin'] = true;
        $_SESSION['wl_cid'] = $u02_2res[0]['company_id'];
        $_SESSION['wl_uid'] = $u02_2res[0]['user_id'];
        $_SESSION['wl_uname'] = $u02_2res[0]['user_name'];
    }
    
    echo json_encode(array(
        'success' => true
    ));
    return;
} catch (PDOException $e) {
    echo json_encode(array(
        'success' => false,
        'msg' => "数据库连接失败，请联系管理员！"
    ));
    return;
}

?>